import {
  queryJiraData,
  queryTestData,
  querySingleProjectId,
  querySingleQualitySum,
  queryJiraDbEachMonthBug
} from '../services/api';

import moment from 'moment';
import { stat } from 'fs';

export default {
  namespace: 'singpro',

  state: {

    Singlebug: {    
      singleporjectId: '',
      singleprojectName:'',
      singlebugTotal: '',
      singlebugNumWeekGrowth:  '',
      singlebugNumDayGrowth: '',
      singlebugHandingRate: '',
      singlebugHandingWeekGrowth: '',
      singlebugHandingDayGrowth: '',
      singlebugMonthDetail:[],
      singlebugMonthTotal:'',
      singlebugMonthMax:'',
      singleBugDayAverage:'',
      singleBugMonthTotalBug:[],
      singlequalityRegression:[],
      singlequalityHandingRate:[]
    },
    SinglequalitySum:{
      qualitysum:[]
    },
    SelectEachYear:{
      monthData:[],
    }
      

  },

  effects: {

    // 当项目请求传递参数
        *fetchSingleProjectId({payload}, { put, call }) {
          let {projectId} = payload;
          const response = yield call(querySingleProjectId,projectId);
          
          yield put({
            type: 'change',
            payload: { Singlebug: response.data},
          });
        },


        *fetchqualitysum(_,{put,call}){

          const  response =yield call(querySingleQualitySum);

          yield put({
            type:'concat',
            payload:{SinglequalitySum: response.data },
          })
        },

        *fetchJiraDbBug({payload},{put,call}){
          let {year,projectId}=payload;
          const response =yield call (queryJiraDbEachMonthBug,year,projectId);
         // console.log('99999999',response)

          yield put({
            type:'concat',
            payload:{SelectEachYear: {monthData:response.data} },
          })
        },
        
  },

  reducers: {
    change(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    concat(state,{payload}){
      return{
        ...state,
        ...payload,
      }
    }
  },
};
